﻿package code {
	// keyboard manager from beginning of the course
	import flash.display.*;
	import flash.events.*;
	import flash.ui.*;
	
	public class KeyboardManager {
		public var isActive:Boolean;
		public var up:Boolean;
		public var down:Boolean;
		public var right:Boolean;		
		public var left:Boolean;
		public var space:Boolean;
		
		public function KeyboardManager(top:MainGame) {
			top.stage.addEventListener(KeyboardEvent.KEY_DOWN, doKeyDown);
			top.stage.addEventListener(KeyboardEvent.KEY_UP, doKeyUp);
		}
		
		public function doKeyDown(anEvent:KeyboardEvent):void {
			if (isActive) {
				switch (anEvent.keyCode) {
					case Keyboard.UP:    up    = true; break;
					case Keyboard.DOWN:	 down  = true; break;
					case Keyboard.RIGHT: right = true; break;
					case Keyboard.LEFT:	 left  = true; break;
					case Keyboard.SPACE: space = true; break;
				}
			}
		}
		
		public function doKeyUp(anEvent:KeyboardEvent):void {
			if (isActive) {
				switch (anEvent.keyCode) {
					case Keyboard.UP:	  up    = false; break;
					case Keyboard.DOWN:	  down  = false; break;
					case Keyboard.RIGHT:  right = false; break;
					case Keyboard.LEFT:	  left  = false; break;
					case Keyboard.SPACE: space = false; break;
				}
			}
		}
		
	} // Class KeyboardManager
	
} // Package Problem5